export function createId(salt){
  let res = [], hex = '0123456789ABCDEF';
  salt = salt || Math.floor(Math.random() * Date.now());

  for (var i = 0; i < 36; i++) res[i] = Math.floor(Math.random()*0x10);

  res[14] = 4;
  res[19] = (res[19] & 0x3) | 0x8;

  for (let i = 0; i < 36; i++) res[i] = hex[res[i]];

  res[8] = res[13] = res[18] = res[23] = '-';

  return "id-" + res.join('') + `-${salt}`;
}

export function findWidgetType(widgetTypes , widgetTypeId){
  let widgetType = null;
  widgetTypes.forEach(
    item => {
      item.children.forEach(
        itemWidget => {
          if(itemWidget.id === widgetTypeId){
            widgetType = JSON.parse(JSON.stringify(itemWidget));
          }
        }
      )
    }
  )
  return widgetType;
}

export default {
  createId,
  findWidgetType
}